package com.qf.service.impl;

import com.qf.dao.StuDao;
import com.qf.dao.impl.StuDaoImpl;
import com.qf.domain.PageBean;
import com.qf.domain.Stu;
import com.qf.service.StuService;

import java.util.List;

public class StuServiceImpl implements StuService {
    private StuDao stuDao = new StuDaoImpl();
    @Override
    public Stu login(String stuname, String pwd) {
        Stu stu = stuDao.selectByStuname(stuname);
        //判断用户是否存在
        if (!stu.getPwd().equalsIgnoreCase(pwd)){
            throw new RuntimeException("密码错误");
        }
        return stu;
    }

    @Override
    public PageBean<Stu> findByPage(int page_num, int page_size) {
        long totalSize = stuDao.selectCount();
        List<Stu> data = stuDao.selectByPage(page_num,page_size);
        PageBean<Stu> pageBean = new PageBean<>(page_size,page_num,totalSize,data);
        return pageBean;
    }

    @Override
    public void delete(int id) {
        stuDao.deleteById(id);
    }

    @Override
    public Stu findById(int id) {
        Stu stu = stuDao.selectById(id);
        return stu;
    }

    @Override
    public void updateStu(Stu stu) {
        stuDao.update(stu);
    }
}
